package com.lingkang.dbtodoc.config;

import com.lingkang.dbtodoc.constants.DataBaseType;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 绫小路
 * @date 2021/1/31 23:21
 * @description
 */
@Component
public class AuthFilter implements Filter {

  @Autowired
  private HttpServletRequest httpServletRequest;
  @Autowired
  private DataBaseType dataBaseType;

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//    if (httpServletRequest.getSession().getAttribute("username") == null) {
//      response.setContentType("text/html;charset=utf-8");
//      PrintWriter writer = response.getWriter();
//      writer.print("<script>alert('您还未登陆！');window.location.href='/login'</script>");
//      writer.flush();
//      return;
//    }

//    if (dataBaseType.getType()==null){
//            response.setContentType("application/json");
//      response.setCharacterEncoding("utf-8");
//      PrintWriter writer = response.getWriter();
//      writer.print("{\"code\":1},\"msg\":\"未配置数据源，无法执行该操作\"");
//      writer.flush();
//      return;
//    }
    chain.doFilter(request, response);
  }
}
